package com.scm.web.controller.project;

import java.util.List;

import com.scm.common.core.domain.entity.SysUser;
import com.scm.common.core.page.PageDomain;
import com.scm.common.core.page.TableSupport;
import com.scm.persist.model.ScmProject;
import com.scm.service.IScmProjectService;
import com.scm.web.controller.product.ProductVO;
import org.apache.commons.compress.utils.Lists;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.scm.common.annotation.Log;
import com.scm.common.enums.BusinessType;
import com.scm.common.core.controller.BaseController;
import com.scm.common.core.domain.AjaxResult;
import com.scm.common.utils.poi.ExcelUtil;
import com.scm.common.core.page.TableDataInfo;

/**
 * 项目Controller
 *
 * @author reptilemanager
 * @date 2024-04-20
 */
@Controller
@RequestMapping("/system/project")
public class ScmProjectController extends BaseController
{
    private String prefix = "project";

    @Autowired
    private IScmProjectService scmProjectService;

    @GetMapping("/projectListPage")
    public String projectListPage( ModelMap mmap)
    {

        return prefix + "/projectList";
    }

    /**
     * 查询订单主列表
     */
    @PostMapping("/projectList")
    @ResponseBody
    public TableDataInfo popupList(ScmProject scmProject)
    {
        List<ScmProject> list = scmProjectService.selectScmProjectList(scmProject);
        return getDataTable(list);
    }

    @PostMapping("/detail/{id}")
    @ResponseBody
    public AjaxResult detail(@PathVariable("id") Long id)
    {
        /*ScmProject scmProject = new ScmProject();
        scmProject.setId(11L);
        scmProject.setProjectName("项目名称");
        scmProject.setContactPerson("联系人xxx");
        scmProject.setTel("12121");
        scmProject.setEmail("5454564@qq.com");
        scmProject.setRemark("asfasfas");*/
        SysUser sysUser = getSysUser();
        ScmProject scmProject = scmProjectService.selectScmProjectById(sysUser.getTenantId(), id);
        return AjaxResult.success(scmProject);

    }



    @RequiresPermissions("system:project:view")
    @GetMapping()
    public String project()
    {
        return prefix + "/project";
    }

    /**
     * 查询项目列表
     */
    @RequiresPermissions("system:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScmProject scmProject)
    {
        startPage();
        List<ScmProject> list = scmProjectService.selectScmProjectList(scmProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @RequiresPermissions("system:project:export")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScmProject scmProject)
    {
        List<ScmProject> list = scmProjectService.selectScmProjectList(scmProject);
        ExcelUtil<ScmProject> util = new ExcelUtil<ScmProject>(ScmProject.class);
        return util.exportExcel(list, "项目数据");
    }

    /**
     * 新增项目
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目
     */
    @RequiresPermissions("system:project:add")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScmProject scmProject)
    {
        SysUser sysUser = getSysUser();
        return toAjax(scmProjectService.insertScmProject(scmProject,sysUser));
    }

    /**
     * 修改项目
     */
    @RequiresPermissions("system:project:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysUser sysUser = getSysUser();
        ScmProject scmProject = scmProjectService.selectScmProjectById(sysUser.getTenantId(),id);
        mmap.put("scmProject", scmProject);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目
     */
    @RequiresPermissions("system:project:edit")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScmProject scmProject)
    {
        SysUser sysUser = getSysUser();
        return toAjax(scmProjectService.updateScmProject(scmProject,sysUser));
    }

    /**
     * 删除项目
     */
    @RequiresPermissions("system:project:remove")
    @Log(title = "项目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scmProjectService.deleteScmProjectByIds(ids));
    }
}
